home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / src / WBBump_src.lha / WBBump_src / Plugins / null.wbbplugin.e < prev   
Encoding:
Text File  |  1999-06-30  |  5.2 KB  |  271 lines

  1. /* **************** */
  2. /* null.wbbplugin.e */
  3. /* **************** */
  4.  
  5.  
  6.  
  7. /*
  8.     WBBump - Bumpmapping on the Workbench!
  9.  
  10.     Copyright (C) 1999  Thomas Jensen - dm98411@edb.tietgen.dk
  11.  
  12.     This program is free software; you can redistribute it and/or modify
  13.     it under the terms of the GNU General Public License as published by
  14.     the Free Software Foundation; either version 2 of the License, or
  15.     (at your option) any later version.
  16.  
  17.     This program is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.     GNU General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU General Public License
  23.     along with this program; if not, write to the Free Software Foundation,
  24.     Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  25. */
  26.  
  27.  
  28.  
  29. /*
  30.     Example plugin for WBBump
  31.     does nothing at all, but serves as an example / skeleton
  32. */
  33.  
  34. OPT PREPROCESS
  35.  
  36.  
  37.  
  38. LIBRARY 'null.wbbplugin', 1, 0, 'null.wbbplugin 1.0 (1/5/99)' IS
  39.     pluginInit(A0), pluginCleanup(),
  40.     pluginInitInstance(A0), pluginFreeInstance(A0),
  41.     pluginGetAttr(D1,D2,A0), pluginSetAttr(D1,D2,D3),
  42.     pluginDoAction(A0,A1,A2,A3)
  43.  
  44.  
  45.  
  46.  
  47.  
  48. /* just to put flags in top of source */
  49.  
  50. #define    ARGTEMPLATE      ''
  51. #define    PLUGINTYPE      PLUGINTYPE_BUMPER
  52. CONST    ISMODIFIER    = TRUE                -> this is a modifying plugin
  53. CONST    ISSTATIC    = TRUE                -> this is a static plugin (see plugin.e)
  54.  
  55.  
  56. /* needed modules */
  57.  
  58. MODULE    'utility',
  59.         'utility/tagitem'
  60.  
  61.  
  62. MODULE    '*/plugin_const'
  63.  
  64.  
  65.  
  66.  
  67. OBJECT handle
  68.     width    :    LONG
  69.     height    :    LONG
  70.     args    :    PTR TO CHAR
  71.     firstrun:    LONG
  72. ENDOBJECT
  73.  
  74.  
  75.  
  76.  
  77.  
  78. PROC main()
  79.     /* library init code here */
  80.     /* this is executed in Forbid() so be carefull */
  81.     /* better use pluginInit() for most things */
  82.  
  83.     /* we need utility.library for GetTagData() */
  84.     IF (utilitybase := OpenLibrary('utility.library', 37)) = NIL THEN RETURN FALSE
  85.  
  86. ENDPROC
  87.  
  88.  
  89.  
  90. PROC close()
  91.     /* free stuff allocated in main() here */
  92.  
  93.     IF utilitybase THEN CloseLibrary(utilitybase)
  94.  
  95. ENDPROC
  96.  
  97.  
  98.  
  99.  
  100. PROC pluginInit(tags:PTR TO tagitem)
  101.     /* do initializations that can't be done in main() here */
  102.     /* read files, etc. */
  103. ENDPROC TRUE
  104.  
  105.  
  106.  
  107.  
  108. PROC pluginCleanup()
  109.     /* cleanup things done in pluginInit() */
  110.  
  111. ENDPROC
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. /* init an instance */
  119.  
  120. PROC pluginInitInstance(tags:PTR TO tagitem)
  121.     DEF    h=NIL:PTR TO handle
  122.  
  123.     /* this function is allways called by WBBump */
  124.     /* use it to allocate buffers, open libraries, etc */
  125.  
  126.     /* return a handle to an "instance" */
  127.  
  128.  
  129.  
  130.     /* alloc handle */
  131.     NEW h
  132.  
  133.  
  134.     /* set global vars */
  135.  
  136.     IF tags
  137.         h.width        := GetTagData(PLUGINTAG_WIDTH, -1, tags)
  138.         h.height    := GetTagData(PLUGINTAG_HEIGHT, -1, tags)
  139.         h.args        := GetTagData(PLUGINTAG_ARGS, NIL, tags)
  140.         h.firstrun    := TRUE
  141.     ENDIF
  142.  
  143.     IF (h.width=-1) OR (h.height=-1) THEN RETURN NIL
  144.  
  145.     /* return NIL if there was an error */
  146.  
  147. ENDPROC h
  148.  
  149.  
  150. /* free an instance */ 
  151.  
  152. PROC pluginFreeInstance(h:PTR TO handle)
  153.     DEF    dummy
  154.  
  155.     /* cleanup stuff allocated in pluginInitInstance() */
  156.  
  157. ENDPROC
  158.  
  159.  
  160.  
  161. PROC pluginGetAttr(h:PTR TO handle, attr, valueptr:PTR TO LONG)
  162.  
  163.     /* this is where WBBump gets information from the plugin */
  164.     /* look in plugin.e to see what is required */
  165.  
  166.     IF h
  167.         SELECT attr
  168.  
  169.         CASE PLUGINTAG_WIDTH
  170.             valueptr[0] := h.width    -> return the width
  171.             RETURN TRUE
  172.  
  173.         CASE PLUGINTAG_HEIGHT
  174.             valueptr[0] := h.height    -> return the height
  175.             RETURN TRUE
  176.  
  177.         CASE PLUGINTAG_NEEDUPDATE
  178.             IF h.firstrun
  179.                 valueptr[0] := TRUE
  180.                 h.firstrun := FALSE
  181.             ELSE
  182.                 valueptr[0] := FALSE
  183.             ENDIF
  184.             RETURN TRUE
  185.  
  186.         ENDSELECT
  187.     ENDIF
  188.  
  189.     SELECT attr
  190.  
  191.     CASE PLUGINTAG_WIDTH
  192.         valueptr[0] := -1
  193.         RETURN TRUE
  194.  
  195.     CASE PLUGINTAG_HEIGHT
  196.         valueptr[0] := -1
  197.         RETURN TRUE
  198.  
  199.     CASE PLUGINTAG_ISMODIFIER
  200.         valueptr[0] := ISMODIFIER    -> see top of file
  201.         RETURN TRUE
  202.  
  203.     CASE PLUGINTAG_COMMANDNAME
  204.         valueptr[0] := 'PLUGIN_NULL'-> tooltypes command
  205.         RETURN TRUE
  206.  
  207.     CASE PLUGINTAG_ISSTATIC
  208.         valueptr[0] := ISSTATIC        -> see top of file
  209.         RETURN TRUE
  210.  
  211.     CASE PLUGINTAG_NEEDUPDATE
  212.         valueptr[0] := FALSE        -> this plugin never needs update
  213.         RETURN TRUE
  214.  
  215.     CASE PLUGINTAG_TYPE
  216.         valueptr[0] := PLUGINTYPE
  217.         RETURN TRUE
  218.  
  219.     CASE PLUGINTAG_NAME
  220.         valueptr[0] := 'null.wbbplugin'
  221.         RETURN TRUE
  222.  
  223.     CASE PLUGINTAG_COPYRIGHT
  224.         valueptr[0] := '©1999 Thomas Jensen - dm98411@edb.tietgen.dk'
  225.         RETURN TRUE
  226.  
  227.     CASE PLUGINTAG_AUTHOR
  228.         valueptr[0] := 'Thomas Jensen - dm98411@edb.tietgen.dk'
  229.         RETURN TRUE
  230.  
  231.     CASE PLUGINTAG_DESC
  232.         valueptr[0] := 'Does nothing at all, just a demonstration of a plugin'
  233.         RETURN TRUE
  234.  
  235.     DEFAULT
  236.         RETURN FALSE            -> return false if the tag is unknown
  237.  
  238.     ENDSELECT
  239.  
  240. ENDPROC FALSE
  241.  
  242.  
  243.  
  244. PROC pluginSetAttr(h:PTR TO handle, attr, value)
  245.  
  246.     /* later this may be used to set plugin attributes */
  247.     /* if there's no attributes to set, return FALSE */
  248.  
  249. ENDPROC FALSE
  250.  
  251.  
  252.  
  253.  
  254. PROC pluginDoAction(h:PTR TO handle, inbuf:PTR TO CHAR, outbuf:PTR TO CHAR, tags:PTR TO tagitem)
  255.     DEF    i=0
  256.  
  257.     /* this is the "action" part of the plugin */
  258.     /* it is called each time the plugin's services are needed */
  259.     /* if the plugin says TRUE to ISMODIFIER then inbuf contain an image */
  260.     /* othervice it a NIL pointer */
  261.     /* tags is currently not used */
  262.  
  263.     IF inbuf
  264.         CopyMem(inbuf, outbuf, h.width * h.height)
  265.     ELSE
  266.         FOR i := 0 TO (h.width * h.height) - 1 DO outbuf[i] := 0
  267.     ENDIF
  268.  
  269.     /* return FALSE if something went wrong */
  270. ENDPROC TRUE
  271.